package com.xxjqr.rbac.enums;

import com.baomidou.mybatisplus.annotation.EnumValue;
import com.fasterxml.jackson.annotation.JsonCreator;
import com.fasterxml.jackson.annotation.JsonValue;
import lombok.AllArgsConstructor;
import lombok.Getter;

@Getter
@AllArgsConstructor
public enum StatusEnum implements BaseEnum{
    ENABLE(1,"正常"),
    DISABLE(0,"禁用")
    ;

    @EnumValue
    @JsonValue
    private final Integer code;
    private final String desc;


    //当版本降为2.10.5时能正常运行，2.11版本只能将@JsonCreator修改为@JsonCreator(mode = JsonCreator.Mode.DELEGATING)
    @JsonCreator(mode = JsonCreator.Mode.DELEGATING)
    public static StatusEnum valueOf(int code) {
        //StatusEnum.values() == values()
        for (StatusEnum statusEnum : values()) {
            if (statusEnum.code == code) {
                return statusEnum;
            }
        }
        return null;
    }

    @Override
    public String getName() {
        return name();
    }
}
